package top.lcm889.oj.leetcodeTop200;

/**
 * @author Coder-lcm
 * @date 2021/4/5
 */
public class LC124_二叉树的最大路径和 {
    static int ans = 0;
    public static int maxPathSum(TreeNode root) {
        if (root == null) return 0;
        int left = Math.max(0, maxPathSum(root.left));
        int right = Math.max(0, maxPathSum(root.right));
        ans = Math.max(ans, left + right + right);
        return Math.max(left, right) + root.val;
    }

    public static void main(String[] args) {

    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
         this.val = val;
         this.left = left;
         this.right = right;
    }
 }
